
package com.hc.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.hc.dao.INodesDao;
import com.hc.domain.Nodes;
import com.hc.util.LoggerUtil;
@Repository
public class NodesDaoImpl extends BaseDaoImpl<Nodes> implements INodesDao {

	@Override
	public List<Nodes> getNodesByAdminId(int id) {
		String sql = "SELECT n.* FROM user_and_role u,role ro ,role_and_nodes r, nodes n WHERE u.adminId=? AND ro.id = u.roleId  AND r.roleId = ro.id AND n.id = r.nodeId";
		try {
			return super.executeSql(Nodes.class, sql, new Object[]{id+""});
		} catch (Exception e) {
			return null;
		}
		
	}

	@Override
	public List<Nodes> getNodesByAdminIdAndParentId(int adminId, int praentId) {
		String sql = "SELECT n.* FROM user_and_role u,role ro ,role_and_nodes r, nodes n WHERE u.adminId=? AND ro.id = u.roleId  AND r.roleId = ro.id AND n.id = r.nodeId AND n.parentId=?";
		try {
			return super.executeSql(Nodes.class, sql, new Object[]{adminId,praentId});
		} catch (Exception e) {
			LoggerUtil.error(e);
			return null;
		}
		
	}

}

